<?php
require('../../../lib/base.php');
$base=new base('web');
$captcha=$base->library('captcha');
$helper=$base->library('helper');
if($base->post('back',true)){
	define('HTTP_REFERER',$base->post('back',true));
}else{
	define('HTTP_REFERER',domain);
}
if(!$captcha->check($base->post('captcha',true),600)){
	$helper->SMessage(5,domain.'view/Login.php?back='.HTTP_REFERER,"no","验证码错误,5秒后转到登陆页");
	exit();
}
$mail=strtolower($base->post('mail',true));
$password=$base->post('password',true);
if(!$helper->CMail($mail)||strlen($password)<6||strlen($password)>32){
	$helper->SMessage(5,domain.'view/Login.php?back='.HTTP_REFERER,"no","您输入的参数有误,5秒后转到登陆页");
	exit();
}
$member=$base->model('member');
$user=$member->GMember(array('where'=>array('mail ='=>$mail)));
$user=reset($user);
if(empty($user)){
	$helper->SMessage(5,domain.'view/Login.php?back='.HTTP_REFERER,"no","这个帐户不存在,请确认后再登陆.");
	exit();
}else if($user['password']!==$password){
	$helper->SMessage(5,domain.'view/Login.php?back='.HTTP_REFERER,"no","帐户与密码不匹配,请注意大小写.");
	exit();
}else if($user['visits']==0&&$user['locked']==1){
	$helper->SMessage(5,domain.'view/mailok.php?mail='.$mail,"no","帐户未激活,请前往激活.");
	exit();
}else{
	$member->UMember(array('set'=>array('visits=visits+'=>1,'ip ='=>ip2long($_SERVER["REMOTE_ADDR"]),'date ='=>$base->runtime),'where'=>array('mail ='=>$mail,'password ='=>$password)));
	$mation=$base->model('information');
	$info=$mation->GMation(array('where'=>array('member ='=>$user['id'])));
	$info=reset($info);
	$transform=$base->model('data');
	$commision=reset($transform->select('transform',array('select'=>'SUM(commision) AS commision','where'=>array('locked='=>1,'member='=>$user['id']))));
	$commision=number_format(floatval($commision['commision']),2);
	$bank=$base->model('bank');
	$bank=reset($bank->GBank(array('select'=>'name','where'=>array('member='=>$user['id']))));
	$bank=empty($bank['name'])?'未设置':$bank['name'];
	$session=$base->library('session');
	$session->SVAR('member',$user['id']);
	$session->SVAR('commision',$commision);
	$session->SVAR('bank',$bank);
	$session->SVAR('mail',$mail);
	$session->SVAR('name',$info['name']);
	$session->SVAR('money',$info['money']);
	$session->SVAR('frozen',$info['frozen']);
	$session->SVAR('role',$user['role']);
	$session->SVAR('visits',$user['visits']);
	$session->SVAR('ip',$user['ip']);
	$session->SVAR('date',$user['date']);
	$helper->SMessage(5,domain.'home/index.php',"yes","登录成功,5秒后转到用户中心");
}
?>